/** \file    winver.cpp
  * \brief   Simple and fast functions for Windows version determination.
  * \date    2003
  * \author  Fedor Chelnokov
  * \version $Header: /home/cscom1r4/cvsroot/cs/mswin/src/winver.cpp,v 1.1 2004/01/23 21:29:35 cscom1r4 Exp $
  */

#include "mswin/winver.h"

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

namespace mswin {

static bool has_version_info = false;
static OSVERSIONINFO version_info;

static void get_version_info()
{
	if (has_version_info)
		return;
	version_info.dwOSVersionInfoSize = sizeof(version_info);
	GetVersionEx(&version_info);
	has_version_info = true;
	return;
}

void get_winver(unsigned & major, unsigned & minor, unsigned & build, unsigned & platform)
{
	get_version_info();
	major = version_info.dwMajorVersion;
	minor = version_info.dwMinorVersion;
	build = version_info.dwBuildNumber;
	platform = version_info.dwPlatformId;
}

bool is_win95()
{
	get_version_info();
	return version_info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS;
}

bool is_win98()
{
	get_version_info();
	return version_info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS
		&& version_info.dwMajorVersion >= 4
		&& version_info.dwMinorVersion >= 10;
}

bool is_winME()
{
	get_version_info();
	return version_info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS
		&& version_info.dwMajorVersion >= 4
		&& version_info.dwMinorVersion >= 90;
}

bool is_winNT()
{
	get_version_info();
	return version_info.dwPlatformId == VER_PLATFORM_WIN32_NT;
}

bool is_win2000()
{
	get_version_info();
	return version_info.dwPlatformId == VER_PLATFORM_WIN32_NT
		&& version_info.dwMajorVersion >= 5;
}

bool is_winXP()
{
	get_version_info();
	return version_info.dwPlatformId == VER_PLATFORM_WIN32_NT
		&& version_info.dwMajorVersion >= 5
		&& version_info.dwMinorVersion >= 1;
}

bool is_win2003()
{
	get_version_info();
	return version_info.dwPlatformId == VER_PLATFORM_WIN32_NT
		&& version_info.dwMajorVersion >= 5
		&& version_info.dwMinorVersion >= 2;
}

} //namespace mswin
